    //
//  CommonActivity.m
//  WRY
//
//  Created by zhong sckj on 10-10-15.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "CommonActivity_iPad.h"


@implementation CommonActivity_iPad

- (void)showLoading:(float)centerx centerY:(float)centery {
	if (loadingLabel == nil) {
		float centerX;
		float centerY;
		
		if (centerx>0 && centery>0) {
			centerX =centerx;
			centerY = centery;
		}
		else {
			centerX = self.view.frame.size.width/2;
			centerY = self.view.frame.size.height/2;
		}

		
		CGPoint center = CGPointMake(centerX, centerY);
		
		loadingBackImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"but90x30.png"]];
		loadingBackImage.frame = CGRectMake(0.0f, 0.0f,90.0f, 30.0f);
		loadingBackImage.center = center;
		[self.view addSubview:loadingBackImage];
		
		loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 90.0f, 30.0f)];
		loadingLabel.font = [UIFont boldSystemFontOfSize:12.0f];
		loadingLabel.backgroundColor = [UIColor clearColor];
		loadingLabel.text = @"加载中...";
		loadingLabel.textColor = [UIColor darkGrayColor];
		loadingLabel.center = CGPointMake(centerX+32, centerY);
		[self.view addSubview:loadingLabel];
		activeIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
		activeIndicator.center = CGPointMake(centerX - 28, centerY);
		[self.view addSubview:activeIndicator];
		
	}
	self.view.userInteractionEnabled = NO;
	loadingBackImage.hidden = NO;
	activeIndicator.hidden = NO;
	[activeIndicator startAnimating];
	loadingLabel.hidden = NO;
	[self.view bringSubviewToFront:loadingBackImage];
	[self.view bringSubviewToFront:activeIndicator];
	[self.view bringSubviewToFront:loadingLabel];
}
-(void)showAlertMessage:(NSString *)message
{
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
}
- (void)hideLoading {
	[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
	self.view.userInteractionEnabled = YES;
	loadingBackImage.hidden = YES;
	activeIndicator.hidden = YES;
	[activeIndicator stopAnimating];
	loadingLabel.hidden = YES;
}
- (void)showConnectionError {
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
													message:@"Connection error" 
												   delegate:nil
										  cancelButtonTitle:@"OK" 
										  otherButtonTitles:nil];
	[alert show];
	[alert release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
	{
		return YES;
	}
    else 
	{
		return NO;
	}
	
}
//-(BOOL)shouldAutorotate
//
//{
//    
//    return YES;
//    
//}
//-(NSUInteger)supportedInterfaceOrientations{
//    
//    return UIInterfaceOrientationMaskLandscape; //UIInterfaceOrientationMaskLandscape、UIInterfaceOrientationMaskAll、UIInterfaceOrientationMaskAllButUpsideDown
//    
//}
- (void)dealloc {
	[loadingLabel release];
	[activeIndicator release];
	[loadingBackImage release];
    [super dealloc];
}


@end
